﻿using System;
using System.Linq;
using System.Collections.Generic;

using Microsoft.Xna.Framework;

using Ah.Testudin.Engine.Graphics;
using Ah.Testudin.Engine.UI.Elements;
using Ah.Testudin.Engine.Input;
using Ah.Testudin.Engine.Events;
using Microsoft.Xna.Framework.Input;

namespace Ah.Testudin.Engine.UI.Views
{
    public class HumanInGameView : HumanViewBase
    {
        #region Private Member Variables

        private readonly FreeMovementController _cameraController;

        private readonly TortoiseController _tortoiseController;

        private readonly IEventManager _eventManager;

        #endregion

        #region Constructors

        public HumanInGameView(
            IList<IScreenElement> screenElements,
            FreeMovementController cameraController,
            TortoiseController tortoiseController,
            ICursor cursor)
            : base(screenElements, cursor)
        {
            if (cameraController == null)
            {
                throw new ArgumentNullException("cameraController");
            }

            if (tortoiseController == null)
            {
                throw new ArgumentNullException("tortoiseController");
            }

            _cameraController = cameraController;

            _tortoiseController = tortoiseController;

            _eventManager = EventManagerSingleton.Instance;
        }

        #endregion

        #region Overrides

        public override bool ProcessInput()
        {
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.GetPressedKeys().Contains(Keys.Escape))
            {
                _eventManager.TriggerEvent(new GamePausedEvent());

                return true;
            }

            return base.ProcessInput();
        }

        public override void Update(GameTime gameTime)
        {
            _cameraController.Update();

            _tortoiseController.Update();

            base.Update(gameTime);
        }

        #endregion
    }
}
